package com.first.agent.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.first.agent.common.JsonResult;
import com.first.agent.service.impl.CustomerServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created with IntelliJ IDEA.
 * User: lxm
 * Date: 2022/11/15 9:40
 * Description:
 * Version: V1.0
 */
@WebServlet("/customer/customerTable")
public class CustomerTableServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取传递的page和limit
        int page = Integer.parseInt(req.getParameter("page"));
        int limit = Integer.parseInt(req.getParameter("limit"));
        //调用service查询数据
        CustomerServiceImp csi=new CustomerServiceImp();
        JsonResult jsonResult = csi.customerTable(page, limit, null);
        //将jsonResult转为json格式传给页面
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.write(JSONObject.toJSONString(jsonResult));
        writer.flush();
        writer.close();

    }
}
